<?php

$m = new Mongo();
$collection = $m->selectDB("messagesdb")->selectCollection("message");

$id = isset($_GET['id']) ? $_GET['id'] : '1';

$query = array('sid' => $id);
$cursor = $collection->find( $query )->limit(20);
?>
<h1><?php echo "Number of messages: ", $cursor->count(), "\n";?></h1>
<table>
  <tr>
    <td>
      ID
    </td>
    <td>
      NICKNAME
    </td>
    <td>
      GENDER
    </td>
    <td>
      AGE
    </td>
    <td>
      SUBJECT
    </td>
  </tr>
<?php while($cursor->hasNext()): ?>
<?php $msg = $cursor->getNext();?>
  <tr>
    <td>
      <?php echo $msg['id'] ?>
    </td>
    <td>
      <?php echo $msg['s_nickname']; ?>
    </td>
    <td>
      <?php echo $msg['s_gender']; ?>
    </td>
    <td>
      <?php echo $msg['s_age']; ?>
    </td>
    <td>
      <?php echo $msg['subject']; ?>
    </td>
  <tr>
<?php endwhile; ?>
</table>